/*
 * @lc app=leetcode.cn id=77 lang=cpp
 *
 * [77] 组合
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    vector<vector<int>> ret;
    vector<int> tmp;
    void dfs(int n,int k,int pos,vector<int>& used) {
        if(tmp.size() == k) {
            ret.push_back(tmp);
            return ;
        }
        for(int i = pos;i <= n;i++) {
            if(used[i] == 1) {
                continue;
            }
            tmp.push_back(i);
            used[i] = 1;
            dfs(n,k,i+1,used);
            used[i] = 0;
            tmp.pop_back();
        }
    }
    vector<vector<int>> combine(int n, int k) {
        vector<int> used(n+1,0);
        dfs(n,k,1,used);
        return ret;
    }
};
// @lc code=end

